<extend name="./Application/Common/View/block/base.php" />
<block name="header">
    <include file="./Application/Admin/View/block/easyui_header.php" />
    <include file="./Application/Admin/View/block/amap_header.php" />
    <link href="__PUBLIC__/css/Content/index.css" rel="stylesheet" type="text/css" />
    <style>
        #dg{
            height: 100%;;
        }
    </style>
    <script>
        $(function(){
            $('#pumpStationTree').tree({
                method: 'get',
                checkbox : false,
                lines: true,
                url : '__URL__/get_pump_station_tree',
                onClick : function(node) {
                    if ($(this).tree('isLeaf', node.target)) {
                        var id = node.id;
                        switchPumpStation(id);
                    }
                    else
                        $('#pumpstation_id').val('');
                    $(".validatebox-tip").remove();
                },
                onLoadSuccess: function (node, data) {
                    //$('#tabs_pumpstation').tabs({height:600,width:960});
                    $('#tabs_pumpstation').tabs({height:$('#subTabCtrl_1').height()-40,width:$('#subTabCtrl_1').width()-50});

                    var firstLeaf=null;
                    if($('#pumpstation_id').val()=="")
                        firstLeaf = getFirstLeafNode();
                    else
                        firstLeaf=$('#pumpStationTree').tree('find', parseInt($('#pumpstation_id').val()));

                    $('#pumpStationTree').tree('select',firstLeaf.target);

                    var id = firstLeaf.id;
                    switchPumpStation(id);
                    $(".validatebox-tip").remove();
                    $('#btnList').linkbutton('enable');

                    $('#btnList').linkbutton('enable');
                    //$('#tabs_pumpstation').tabs('resize');
                }
            });

        });

        function getFirstLeafNode() {
            var node = $('#pumpStationTree').tree('getRoot');
            var children=null;
            while(!$('#pumpStationTree').tree('isLeaf', node.target)) {
                if (node){
                    children = $('#pumpStationTree').tree('getChildren', node.target);
                } else {
                    children = $('#pumpStationTree').tree('getChildren');
                }
                if (children!=null && children.length>0)
                    node = children[0];
            }
            return node;
        }


        function addTreeNode() {
            $('#tabCtrl').tabs('select',0);
            $('#subTabCtrl_1').tabs('select',0);
            $('#tabs_pumpstation').tabs('select',0);
            $('#pumpStationTree').tree('select',$('#pumpStationTree').tree('getRoot').target);
            $('#pumpstation_id').val('');
            $('#pumpstationhydrodynamicsparameter_pumpstationid').val('');
            addPumpstation();
        }

        function deleteTreeNode(){
            var node = $('#pumpStationTree').tree('getSelected');
            var id = node.id;
            if ((node!=null) && (id!=null)) {
                jQuery.messager.confirm('请确认', '你确定要删除吗？', function(r){
                    if (r){
                        $.ajax({
                            url:"__URL__/deleteArray",
                            data:{"ids":id},
                            method: "post",
                            dataType: "json",
                            async: true,
                            success: function(data) {
                                console.log(data);
                                if (data.status==1) {
                                    $('#pumpstation_id').val('');
//                                    $('#pumpstationhydrodynamicsparameter_pumpstationid').val('');
                                    jQuery('#pumpStationTree').tree('reload');
                                    $.messager.show({title:'提示',msg:'删除成功！',showType:'slide'});
                                }
                                else $.messager.alert('提示','删除失败！','error');
                            },
                            error: function(XMLHttpRequest, textStatus, errorThrown) {
                                $.messager.alert('提示','删除出错，错误类型为!'+textStatus,'error');
                            }
                        });
                    }
                });
            }
        }

        function switchPumpStation(id) {
            $('#pumpstation_id').val(id);
            //清空所有form
            $('form').form('clear');
            $("input[name='pumpid']").val(id);
            //刷新说有表格
            $('#grid_pump').datagrid({queryParams:{'pumpid':$('#pumpstation_id').val(),page:1,rows:10}});
            $('#grid_pump_log').datagrid({queryParams:{'pumpid':$('#pumpstation_id').val(),page:1,rows:10}});
            $('#grid_machine').datagrid({queryParams:{'pumpid':$('#pumpstation_id').val(),page:1,rows:10}});
            $('#grid_machine_log').datagrid({queryParams:{'pumpid':$('#pumpstation_id').val(),page:1,rows:10}});
            $('#grid_waterele').datagrid({queryParams:{'pumpid':$('#pumpstation_id').val(),page:1,rows:10}});
            $('#grid_waterele_log').datagrid({queryParams:{'pumpid':$('#pumpstation_id').val(),page:1,rows:10}});
            $('#grid_weather_log').datagrid({queryParams:{'facilities_type':1,'facilities_id':$('#pumpstation_id').val(),page:1,rows:20}});
            //刷新需要的控件
            $('.pump_select').combobox('reload','/Manage/AdminPumpPump/get_all_pump?pumpid='+id);
            $('.machine_select').combobox('reload','/Manage/AdminPumpMachine/get_all_machine?pumpid='+id);
            $('.waterele_select').combobox('reload','/Manage/AdminPumpWaterele/get_all_waterele?pumpid='+id);


//            clearPumpstationForm();
            editPumpstation($('#pumpstation_id').val());
        }

        function listDlg() {
            $('#listDialog').dialog({
                onResize: function(w, h) {
                    $('#dg').datagrid('resize');
                }
            });
            $('#listDialog').dialog({modal:true});
            $('#listDialog').dialog('open');
            $('#listDialog').dialog('maximize');
            $('#dg').datagrid("unselectAll");
        }

    </script>
</block>
<block name="bdoy">
    <body>
    <input type="hidden" id="pumpstation_id" name="pumpstation_id"/>
    <div class="easyui-layout" style="width:100%;height: 500px;"  fit="true">
        <div data-options="region:'west',split:true" title="{:LANG('pump_station')}" style="width:240px;">
            <div id="treeToolBar" style="background:#fafafa;padding:2px;height:auto">
                <a id="btnAdd3" href="#" class="easyui-linkbutton"  onclick="addTreeNode()" iconCls="icon-add" plain="true">增加</a>
                <a id="btnDel3" href="#" class="easyui-linkbutton"  onclick="deleteTreeNode()" iconCls="icon-remove" plain="true">删除</a>
                <a id="btnList" href="#" class="easyui-linkbutton" onclick="listDlg()" iconCls="icon-search" plain="true">搜索</a>
            </div>
            <ul id="pumpStationTree" class="easyui-tree"></ul>
        </div>
        <div data-options="region:'center'">
            <div class="easyui-tabs" id="tabCtrl" fit="true" border="false">
                <div title="泵站基础信息" fit=true  closable="false" style="padding:10px;">
                    <div id="subTabCtrl_1" class="easyui-tabs" fit="true" plain="true" >
                        <div title="泵站基本信息" fit=true style="padding:10px;" href="__URL__/base_info" loadingMessage="{:LANG('loading')}"></div>
                    </div>
                </div>
                <div title="泵机"  closable="false" style="padding:10px;">
                    <div class="easyui-tabs" fit="true" plain="true" style="height:100px;width:300px;" tools="#pumpmonth_toolbars">
                        <div title="泵机列表" style="padding:10px;" href="__URL__/pump_pump" loadingMessage="{:LANG('loading')}" fit="true"></div>
                        <div title="泵机运行记录" style="padding:10px;" href="__URL__/pump_pump_log" loadingMessage="{:LANG('loading')}" fit="true"></div>
                    </div>
                </div>
                <div title="格栅机"  closable="false" style="padding:10px;">
                    <div class="easyui-tabs" fit="true" plain="true" style="height:100px;width:300px;" tools="#pumpmonth_toolbars">
                        <div title="格栅机列表" style="padding:10px;" href="__URL__/pump_machine" loadingMessage="{:LANG('loading')}" fit="true"></div>
                        <div title="格栅机运行记录" style="padding:10px;" href="__URL__/pump_machine_log" loadingMessage="{:LANG('loading')}" fit="true"></div>
                    </div>
                </div>
                <div title="水电表" closable="false" style="padding:10px;">
                    <div tools="#pwvl_toolbars" class="easyui-tabs" fit="true" plain="true" style="height:100px;width:300px;">
                        <div title="水电表" style="padding:10px;" href="__URL__/pump_waterele" loadingMessage="{:LANG('loading')}" fit="true"></div>
                        <div title="水电表运行记录" style="padding:10px;" href="__URL__/pump_waterele_log" loadingMessage="{:LANG('loading')}" fit="true"></div>
                    </div>
                </div>
                <div title="雨情记录" closable="false"  style="padding:10px;">
                    <div class="easyui-tabs" fit="true" plain="true" style="height:100px;width:300px;">
                        <div title="雨情记录" style="padding:10px;" href="__URL__/weather_log" loadingMessage="{:LANG('loading')}" fit="true"></div>
                    </div>
                </div>
            </div>
        </div>

    </div>
    </div>
    <div id="listDialog" class="easyui-dialog" title="泵站列表" closed="true" resizable='true' modal="true" minimizable="false" collapsible="false"  style="left:100px;top:100px;width:620px;height:300px;padding:5px">
        <table id="dg"></table>
        <div id="toolbar" style="padding:5px;height:auto">
            <div style="margin-bottom:5px">
                <!--            <a href="#" id="add_button" class="easyui-linkbutton" iconCls="icon-add" plain="true">{:LANG('add')}</a>-->
                <!--            <a href="#" id="edit_button" class="easyui-linkbutton" iconCls="icon-edit" plain="true">{:LANG('edit')}</a>-->
                <!--            <a href="#" id="del_button" class="easyui-linkbutton" iconCls="icon-remove" plain="true">{:LANG('del')}</a>-->
                <a href="#" id="search_button" class="easyui-linkbutton" iconCls="icon-search" plain="true">{:LANG('search')}</a>
                <a href="#" id="reload_button" class="easyui-linkbutton" iconCls="icon-reload" plain="true">{:LANG('reload')}</a>
                <!--            <a href="#" id="clear_button" class="easyui-linkbutton" iconCls="icon-redo" plain="true">{:LANG('clearSelections')}</a>-->
                双击记录即可选择对应泵站
            </div>
            <div id="queryMaterialsRemovalParamZone">
                <form id="query_form" method="post" action="">
                    <table>
                        <tr>
                            <td>{:LANG('pump_name')}</td>
                            <td><input type="text" class="" name="pups_name" width="100"/></td>
                            <td>泵站基类</td>
                            <td>
                                <select  name="pups_catg3" style="width:100px;">
                                    {:pump_station_base_types_option()}
                                </select>
                            </td>
                            <td>泵站大类</td>
                            <td>
                                <select  name="pups_catg1" style="width:100px;">
                                    {:pump_station_types_option()}
                                </select>
                            </td>
                            <td>泵站小类</td>
                            <td>
                                <select  name="pups_catg2" style="width:100px;">
                                    {:pump_station_types_second_option()}
                                </select>
                            </td>
                            <td>{:LANG('opr')}</td>
                            <td>
                                <select class="easyui-combobox" name="pups_opr" style="width:80px;">
                                    <option value=""></option>
                                    <volist name="duty_persons" id="p">
                                        <option value=",{$p['id']},">{$p['realname']}</option>
                                    </volist>
                                </select>
                            </td>
                            <td><a id="query_button" href="#" class="easyui-linkbutton" iconCls="icon-search">查询</a></td>
                            <td><a href="#" class="easyui-linkbutton" iconCls="icon-undo" onclick="javascript:$('#query_form').form('clear');">重置</a></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
        <script type="text/javascript">
            $(function(){
                    var request_url = '__URL__/get_all';
                    var add_title = '新增';
                    var edit_title = '编辑';
                    jQuery('#dg').datagrid({
                        fit:true,
                        nowrap: false,
                        striped: true,
                        collapsible:false,
                        url:request_url,
                        method:'get',
                        pageNumber:1,
                        pageSize:{:get_kv_val('admin_page_list_num')},
                pageList:[{:get_kv_val('admin_page_list_num')},50,100,200],
            idField:'id',
                remoteSort: false,
                columns:[[
                {field:'ck',title:'', width:80,checkbox:true,align:'center'},
                {field:'id',title:'ID', width:80,align:'center'},
                {field:'pups_name',title:'{:LANG('pump_name')}', width:120,align:'center'},
                {field:'pups_catg3',title:'泵站基类', width:150,align:'center'},
                {field:'pups_catg1',title:'泵站大类', width:150,align:'center'},
                {field:'pups_catg2',title:'泵站小类', width:150,align:'center'},
                {field:'pups_address',title:'泵站地址', width:150,align:'center'},
                {field:'pups_point',title:'{:LANG('gps_point')}', width:150,align:'center'},
                {field:'pups_opr',title:'{:LANG('opr')}', width:150,align:'center'},

            ]],
                pagination:true,
                rownumbers:true,
                singleSelect:false,
                toolbar: '#toolbar',
                onDblClickRow: function(rowIndex, rowData) {
                var treeNode=$('#pumpStationTree').tree('find', parseInt(rowData.id));
                $('#pumpStationTree').tree('select',treeNode.target);
                switchPumpStation(rowData.id);
                $('#listDialog').dialog('close');

            },
            onSelect: function(rowIndex, rowData) {
                var now_rows = jQuery('#dg').datagrid('getSelections');
                if(now_rows.length > 1){
                    $("#edit_button").linkbutton('disable');
                }
            },
            onUnselect: function(rowIndex, rowData) {
                var now_rows = jQuery('#dg').datagrid('getSelections');
                if(now_rows.length < 2){
                    $("#edit_button").linkbutton('enable');
                }
            },
            });
            //按钮事件绑定
            $('#add_button').click(function(){
                open_window(add_title, '__URL__/add');
            });
            $('#edit_button').click(function(){
                var id = jQuery('#dg').datagrid('getSelected');
                if(!id){
                    msgShow('{:LANG('tips')}', '{:LANG('pls_slet_row')}', 'warning');
                }
                open_window('edit_title', '__URL__/edit?id='+id.id);
            });
            $('#del_button').click(function(){
                var id = jQuery('#dg').datagrid('getSelected');
                if(!id){
                    msgShow('{:LANG('tips')}', '{:LANG('pls_slet_row')}', 'warning');
                }
                var ids = jQuery('#dg').datagrid('getSelections');
                var s = '';
                for(var i=0;i<ids.length;i++){
                    s += ids[i].id+',';
                }

                $.post("__URL__/deleteArray",{"ids":s}, function(result){
                    console.log(result);
                    if(result == 1){
                        flowShow('{:LANG('tips')}', '{:LANG('delete_success')}');
                    } else if(result == 0){
                        msgShow('{:LANG('tips')}', '{:LANG('delete_error')}', 'error');
                    }

                });
            });
            $('#search_button').click(function(){
                $('#query_form').toggle();
                $('#dg').datagrid("resize");
            });
            $('#reload_button').click(function(){
                $('#dg').datagrid('load', {});
//                window.location.href = window.location.href;
            });
            $('#reload_clear').click(function(){
                $('#dg').datagrid('clearSelections');
            });

            $('#query_button').click(function(){
                var obj = $('#query_form').serializeJson();
                $('#dg').datagrid('load',obj);
            });
            });
            $('#query_form').hide();

        </script>
    </div>
    <include file="./Application/Admin/View/block/easyui_window.php" />
    </body>
</block>
<block name="footExtendJs">
    <script type="text/javascript">
        $(function(){

        });
    </script>
</block>
